import 'package:demo/app/widgets/line_horizontal.dart';
import 'package:demo/theme/app_colors.dart';
import 'package:demo/theme/app_text_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../../../../model/repay_plan_model.dart';
import '../../../widgets/line_vertical.dart';
import 'repay_plans_controller.dart';

class RepayPlansView extends GetView<RepayPlansController> {
  const RepayPlansView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var cellHeight = 35.w;
    return Scaffold(
      backgroundColor: Color_bg,
      appBar: AppBar(title: Text('还款计划',style: text_title_black)),
      body: Column(children: [
        Container(
          color: Color_white,
          margin: EdgeInsets.only(left: 15.w,right: 15.w,top: 15.w),
          child: Column(
            children: [
              const LineHorizontal(),
              Row(
                children: [
                  LineVertical(height: cellHeight),
                  Container(padding: EdgeInsets.only(left: 15.w), width:57.w,child: Text('期数',style: text_131732_14)),
                  LineVertical(height: cellHeight),
                  Container(padding: EdgeInsets.only(left: 15.w), width:80.w,child: Text('金额',style: text_131732_14)),
                  LineVertical(height: cellHeight),
                  Expanded(child: Padding(
                    padding: EdgeInsets.only(left: 15.w),
                    child: Text('账单日',style: text_131732_14),
                  )),
                  LineVertical(height: cellHeight),
                  Container(padding: EdgeInsets.only(left: 15.w), width:90.w,child: Obx(() => Text(controller.isChoose.value?'请选择':'状态',style: text_131732_14))),
                  LineVertical(height: cellHeight),
                ],
              ),
              const LineHorizontal(),
            ],
          ),
        ),
        Expanded(
          child: Obx(() => ListView.separated(
            shrinkWrap : true,
            padding: EdgeInsets.only(left: 15.w,right: 15.w,bottom: 15.w),
            itemCount: controller.repayPlanList.value.length,
            separatorBuilder: (BuildContext context, int index) => Container(color: Color_line.withOpacity(0.1),height: 0.8),
            itemBuilder: (BuildContext context, int index) {
              var bean = controller.repayPlanList.value[index];
              return getCell(bean,index,cellHeight);
            },
          )),
        ),
        Container(
          decoration: BoxDecoration(
            color: Color_white,
            borderRadius: BorderRadius.vertical(top: Radius.circular(8.w)),
            boxShadow: [
              BoxShadow(
                color: Colors.black12,
                offset: Offset(0.0, 15.w), //阴影xy轴偏移量
                blurRadius: 5.0, //阴影模糊程度
                spreadRadius: 15.w //阴影扩散程度
              )
            ]),
          padding: EdgeInsets.symmetric(horizontal: 15.w,vertical: 9.w),
          width: Get.width,
          child: Row(
            children: [
              RawMaterialButton(
                elevation: 0,
                highlightElevation: 0,
                fillColor:Color_white,
                shape : RoundedRectangleBorder(side : const BorderSide(color: Color_main,width: 1),borderRadius : BorderRadius.all(Radius.circular(20.w))),
                constraints: BoxConstraints.tightFor(width: (Get.width - 45.w) / 2, height: 40.w),
                child: Obx(() => Text(controller.isChoose.value?'取消':'结清',style: text_main_16)),
                onPressed: ()=> controller.settled(),
              ),
              SizedBox(width: 15.w),
              RawMaterialButton(
                elevation: 0,
                highlightElevation: 0,
                fillColor:Color_main,
                shape : RoundedRectangleBorder(borderRadius : BorderRadius.all(Radius.circular(20.w))),
                constraints: BoxConstraints.tightFor(width: (Get.width - 45.w) / 2, height: 40.w),
                child: Text('还款',style: text_white_16),
                onPressed: ()=> controller.repayment(),
              ),
            ],
          ),
        )
      ],),
    );
  }

  Widget getCell(RepayPlan bean,int index,double cellHeight){
    var status = '';
    var color = Color_131732;
    switch(bean.status){ // 还款状态
      case 1:{ // 到期待还款
        status = '待还款';
        color = Color_131732;
        break;
      }
      case 2:{ // 已还款
        status = '已还款';
        color = Color_grey;
        break;
      }
      case 3:{ // 逾期
        status = '已逾期';
        color = Color_red;
        break;
      }
      case 4:{ // 还款中
        status = '还款中';
        color = Color_grey;
        break;
      }
      case 5:{ // 还款失败
        status = '还款失败';
        color = Color_red;
        break;
      }
    }

    return InkWell(
      highlightColor: Colors.transparent, // 透明色
      splashColor: Colors.transparent, // 透明色
      onTap: () => {},
      child: Row(
        children: [
          LineVertical(height: cellHeight),
          Container(color: Color_white,height: cellHeight,alignment:Alignment.center,padding: EdgeInsets.only(left: 15.w,right: 15.w), width:57.w,child: Text('${bean.qs}',style: text_131732_14)),
          LineVertical(height: cellHeight),
          Container(color: Color_white,height: cellHeight,alignment:Alignment.centerLeft,padding: EdgeInsets.only(left: 15.w), width:80.w,child: Text(bean.money,style: text_131732_14)),
          LineVertical(height: cellHeight),
          Expanded(child: Container(
            alignment:Alignment.centerLeft,
            height: cellHeight,
            color: Color_white,
            padding: EdgeInsets.only(left: 15.w),
            child: Text(bean.repayTime,style: text_131732_14),
          )),
          LineVertical(height: cellHeight),
          Obx(() => Container(color: Color_white,alignment:Alignment.centerLeft,height: cellHeight,padding: EdgeInsets.only(left: 15.w), width:90.w,
              child: controller.isChoose.value?
                Checkbox(
                  value: bean.isCheck,
                  onChanged: (value) => controller.check(bean),
                  activeColor: bean.status == 2 || bean.status == 4 ? Color_grey:Color_main,
                  side: MaterialStateBorderSide.resolveWith((Set<MaterialState> states) => BorderSide(width: 2, color: states.contains(MaterialState.selected)?(bean.status == 2 || bean.status == 4?Color_grey:Color_main):Color_grey))
                )
                  :Text(status,style: text_131732_14.copyWith(color: color))
          )),
          LineVertical(height: cellHeight),
        ],
      ),
    );
  }
}
